import java.io.*;

/**
 * @author zyj
 * @date 2022年05月30日 9:40
 */
public class BufferedInputStreamDemo {
    public static void main(String[] args) {
        InputStream in = null;
        BufferedInputStream bis = null;
        try {
            in = new FileInputStream("a.txt");
            bis = new BufferedInputStream(in);
            byte[] b = new byte[1024];
            int length = 0;
           while ((length = bis.read(b)) != -1){
               System.out.println(new String(b,0,length));
           }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //关闭流的时候是先关闭外面的流，在关闭里面的流
            try {
                bis.close();
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
